package com.yq.wiki.controller;

import com.yq.wiki.req.EbookQueryReq;
import com.yq.wiki.req.EbookSaveReq;
import com.yq.wiki.resp.CommonResp;
import com.yq.wiki.resp.EbookQueryResp;
import com.yq.wiki.resp.PageResp;
import com.yq.wiki.service.EbookService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;


/**
 * 尝试启动hello接口
 *
 */

@RestController//一般用来返回字符串
//@Controller//用来返回页面
@RequestMapping("/ebook")
public class EbookController {

    @Resource
    private EbookService ebookService;



    //查询

//    @Valid开启校验规则
    @GetMapping("/list")
    public CommonResp list(@Valid EbookQueryReq req){
        CommonResp<PageResp<EbookQueryResp>> resp = new CommonResp<>();
        PageResp<EbookQueryResp> list = ebookService.list(req);
        resp.setContent(list);
        return resp;
    }
    //保存
    @PostMapping("/save")
    public CommonResp save(@Valid @RequestBody EbookSaveReq req){
        CommonResp resp = new CommonResp<>();
         ebookService.save(req);

        return resp;
    }
    //删除功能
    @DeleteMapping("/delete/{id}")
    public CommonResp delete(@PathVariable Long id){
        CommonResp resp = new CommonResp<>();
        ebookService.delete(id);

        return resp;
    }

}




